﻿//添加必要的动态连接库
using Model;
using System.Collections.Generic;
using DBUtility;


/**
 * 作者：陈杰
 * QQ  : 710782046
 * Email:ovenjackchain@gmail.com
 * Web :http://www.qidian10.com
 */
namespace DAO
{
    public class rolefunDao
    {

        public bool Add_rolefun(rolefun rolefun)
        {
            if (IsExist(rolefun))
                return true;
            if (DbHelperSQL.Insert(rolefun))
                return true;
            else
                return false;
        }
        public bool IsExist(rolefun rolefun)
        {
            string sql = "select * from rolefun where roleid=" + rolefun.roleid + " and funid=" + rolefun.funid;
            if (DbHelperSQL.Query(sql).Tables[0].Rows.Count > 0)
                return true;
            else
                return false;
        }
        public bool DelAllRoleFun(string roleid)
        {
            DbHelperSQL.ExecuteSql("delete from rolefun where roleid=" + roleid);
            return true;
        }
        public bool Del_rolefun(rolefun rolefun)
        {
            if (DbHelperSQL.Delete(rolefun))
                return true;
            else
                return false;
        }
        public bool Update_rolefun(rolefun rolefun)
        {
            if (DbHelperSQL.Update(rolefun))
                return true;
            else
                return false;
        }
        public rolefun FindById_rolefun(int id)
        {
            rolefun model = new rolefun();
            return Common<rolefun>.Dt2Model(model, DbHelperSQL.FindByConditions(model, " pid=" + id.ToString()));
        }
        public IList<rolefun> FindAll_rolefun()
        {
            return Common<rolefun>.Dt2List(DbHelperSQL.FindByConditions(new rolefun(), ""));
        }
        //获得该角色对应的功能模块
        public IList<rolefun> FindFunByRoleId_rolefun(string roleid)
        {
            return Common<rolefun>.Dt2List(DbHelperSQL.FindByConditions(new rolefun(), " roleid='" + roleid + "'"));
        }
        public IList<userfun> FindMyMenu(string roleid)
        {
            if (roleid == "-1") roleid = "1";
            string sql = "select F.funid,F.funno,F.funname,F.fatherid from userfun F,rolefun where rolefun.funid=F.funid and roleid=" + roleid;
            return Common<userfun>.Dt2List(DbHelperSQL.Query(sql).Tables[0]);
        }
    }
}
